package cn.gcyl.module.biz.service.conferenceinvoiceinformation;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.gcyl.module.biz.controller.admin.conferenceinvoiceinformation.vo.*;
import cn.gcyl.module.biz.dal.dataobject.conferenceinvoiceinformation.ConferenceInvoiceInformationDO;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.util.object.BeanUtils;

import cn.gcyl.module.biz.dal.mysql.conferenceinvoiceinformation.ConferenceInvoiceInformationMapper;

import static cn.gcyl.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.gcyl.framework.common.util.collection.CollectionUtils.convertList;
import static cn.gcyl.framework.common.util.collection.CollectionUtils.diffList;
import static cn.gcyl.module.system.enums.ErrorCodeConstants.CONFERENCE_INVOICE_INFORMATION_NOT_EXISTS;

/**
 * 会议报名发票信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ConferenceInvoiceInformationServiceImpl implements ConferenceInvoiceInformationService {

    @Resource
    private ConferenceInvoiceInformationMapper conferenceInvoiceInformationMapper;

    @Override
    public Long createConferenceInvoiceInformation(ConferenceInvoiceInformationSaveReqVO createReqVO) {
        // 插入
        ConferenceInvoiceInformationDO conferenceInvoiceInformation = BeanUtils.toBean(createReqVO, ConferenceInvoiceInformationDO.class);
        conferenceInvoiceInformationMapper.insert(conferenceInvoiceInformation);

        // 返回
        return conferenceInvoiceInformation.getId();
    }

    @Override
    public void updateConferenceInvoiceInformation(ConferenceInvoiceInformationSaveReqVO updateReqVO) {
        // 校验存在
        validateConferenceInvoiceInformationExists(updateReqVO.getId());
        // 更新
        ConferenceInvoiceInformationDO updateObj = BeanUtils.toBean(updateReqVO, ConferenceInvoiceInformationDO.class);
        conferenceInvoiceInformationMapper.updateById(updateObj);
    }

    @Override
    public void deleteConferenceInvoiceInformation(Long id) {
        // 校验存在
        validateConferenceInvoiceInformationExists(id);
        // 删除
        conferenceInvoiceInformationMapper.deleteById(id);
    }

    @Override
        public void deleteConferenceInvoiceInformationListByIds(List<Long> ids) {
        // 删除
        conferenceInvoiceInformationMapper.deleteByIds(ids);
        }


    private void validateConferenceInvoiceInformationExists(Long id) {
        if (conferenceInvoiceInformationMapper.selectById(id) == null) {
            throw exception(CONFERENCE_INVOICE_INFORMATION_NOT_EXISTS);
        }
    }

    @Override
    public ConferenceInvoiceInformationDO getConferenceInvoiceInformation(Long id) {
        return conferenceInvoiceInformationMapper.selectById(id);
    }

    @Override
    public PageResult<ConferenceInvoiceInformationDO> getConferenceInvoiceInformationPage(ConferenceInvoiceInformationPageReqVO pageReqVO) {
        return conferenceInvoiceInformationMapper.selectPage(pageReqVO);
    }

    @Override
    public void createConferenceInvoiceInformationDO(ConferenceInvoiceInformationDO invoiceInformationDO) {
        conferenceInvoiceInformationMapper.insert(invoiceInformationDO);
    }

}